package com.hnyfkj.jyindustry.biz.xiaofei.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.hnyfkj.jyindustry.biz.kehu.dao.UserDao;
import com.hnyfkj.jyindustry.biz.kehu.entity.User;
import com.hnyfkj.jyindustry.biz.xiaofei.dao.XiaofeiLogDao;
import com.hnyfkj.jyindustry.biz.xiaofei.dto.XiaofeiLogInsertDto;
import com.hnyfkj.jyindustry.biz.xiaofei.dto.XiaofeiLogQueryDto;
import com.hnyfkj.jyindustry.biz.xiaofei.dto.XiaofeiLogUpdateDto;
import com.hnyfkj.jyindustry.biz.xiaofei.entity.XiaofeiLog;
import com.hnyfkj.jyindustry.biz.xiaofei.service.XiaofeiLogService;
import com.hnyfkj.jyindustry.common.dto.PageReturnDto;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.BeanUtils;


@Service("xiaofeiLogService")
public class XiaofeiLogServiceImpl extends ServiceImpl<XiaofeiLogDao, XiaofeiLog> implements XiaofeiLogService {


    @Autowired
    private XiaofeiLogDao xiaofeiLogDao;

    @Autowired
    private UserDao userDao;

    @Override
    public PageReturnDto<XiaofeiLog> queryPage(XiaofeiLogQueryDto queryDto) {
        User user = userDao.selectById(queryDto.getId());
        queryDto.setPhone(user.getPhone());
        PageInfo<XiaofeiLog> page =
                PageHelper.startPage(queryDto.getPage(), queryDto.getLimit()).doSelectPageInfo(() -> xiaofeiLogDao.selectListByQuery(queryDto));
        return PageReturnDto.pageOf(page);
    }

    @Override
    public int insert(XiaofeiLogInsertDto xiaofeiLogInsertDto) {
        final XiaofeiLog xiaofeiLog = new XiaofeiLog();
        BeanUtils.copyProperties(xiaofeiLogInsertDto, xiaofeiLog);
        return xiaofeiLogDao.updateById(xiaofeiLog);
    }

    @Override
    public int update(XiaofeiLogUpdateDto xiaofeiLogUpdateDto) {
        final XiaofeiLog xiaofeiLog = new XiaofeiLog();
        BeanUtils.copyProperties(xiaofeiLogUpdateDto, xiaofeiLog);
        return xiaofeiLogDao.updateById(xiaofeiLog);
    }


}